/*
 * ControllerState.h
 *
 *  Created on: Oct 27, 2012
 *      Author: nam20485
 */

#ifndef CONTROLLERSTATE_H_
#define CONTROLLERSTATE_H_

class ControllerState {
public:
	enum BUTTON
	{
		A		= 1 << 0,
		B		= 1 << 1,
		UP		= 1 << 2,
		DOWN	= 1 << 3,
		LEFT	= 1 << 4,
		RIGHT	= 1 << 5,
		SELECT	= 1 << 6,
		START	= 1 << 7,
	};

	ControllerState(int dataPin, int latchPin, int clockPin)
		: m_state(0)
		, DATA_PIN(dataPin)
		, LATCH_PIN(latchPin)
		, CLOCK_PIN(clockPin)
	{
		// ready to read after construction
		initialize();
		refresh();
	}
	virtual ~ControllerState();

	// refresh button state
	virtual void refresh()		{ }
	virtual void initialize()		{ }

	inline bool buttonIsPressed(BUTTON button) const	{ return (m_state & button); }
protected:
	int m_state;

	const int DATA_PIN;
	const int LATCH_PIN;
	const int CLOCK_PIN;
};

#endif /* CONTROLLERSTATE_H_ */
